package com.zcp.controller;


import com.zcp.entity.Tag;
import com.zcp.entity.address;
import com.zcp.entity.class_z;
import com.zcp.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("class")
public class ClassController {


    @Autowired
    private ClassService classService;

    @RequestMapping("save")
    public String save(class_z class_z){
        classService.save(class_z);
        return "redirect:/class/findAll";
    }

    @RequestMapping("findAll")
    public String findAll(Model model){
        List<class_z> class_zs = classService.findAll();
        model.addAttribute("classes",class_zs);
        return "back/class/index";
    }
    @GetMapping("change/{id}")
    public String change(@PathVariable("id") Integer id, Model model){
        class_z class_z = classService.change(id);
        model.addAttribute("class_z",class_z);
        return "back/class/change";
    }

    @RequestMapping("changed")
    public String changeed(class_z class_z){
        classService.changed(class_z);
        return "redirect:/class/findAll";
    }
    @GetMapping("delete/{id}")
    public String delete(@PathVariable("id") Integer id){
        classService.delete(id);
        return "redirect:/class/findAll";
    }
}
